//
//  JSettingController.m
//  HeadIndustry
//
//  Created by jun on 2017/9/12.
//  Copyright © 2017年 jun. All rights reserved.
//

#import "JSettingController.h"

#import "JUserInfoController.h" // 个人资料
#import "JAddressController.h" // 管理收货地址
#import "JAboutController.h" // 关于头行
#import "JFeedbackController.h" // 意见反馈

@interface JSettingController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, copy) NSArray *dataArr;

@end

@implementation JSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    [super InitUI];
    self.titleLabel.text = @"设置";
    self.leftButton.hidden = NO;
    self.rightButton. hidden = YES;
    [self.leftButton setImage:[UIImage imageNamed:backBtnImg] forState:UIControlStateNormal];
    self.leftButton.frame = CGRectMake(8, self.leftButton.frame.origin.y, 30, 30);
    
    [self setConfigTableView];
}

- (void)setConfigTableView {
    self.automaticallyAdjustsScrollViewInsets = self;
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWindowW, CGRectGetHeight(self.contentView.frame)) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    tableView.backgroundColor = kRGBColor(247, 247, 247);
    tableView.scrollEnabled = NO;
    [self.contentView addSubview:tableView];

    _dataArr = @[@[@"个人资料",@"收货地址管理"],@[@"关于头行",@"意见反馈"]];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _dataArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_dataArr[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    
    cell.textLabel.text = _dataArr[indexPath.section][indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 0) {
        CALayer *line1 = [CALayer layer];
        line1.backgroundColor = kRGBColor(150, 150, 150).CGColor;
        line1.frame = CGRectMake(15, cell.bottom - 0.5, kWindowW - 30, 0.5);
        [cell.contentView.layer addSublayer:line1];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [SVProgressHUD dismiss];
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            JUserInfoController *userInfoVC = [[JUserInfoController alloc]init];
            [self.navigationController pushViewController:userInfoVC animated:YES];
        }
        else
        {
            JAddressController *userInfoVC = [[JAddressController alloc]init];
            [self.navigationController pushViewController:userInfoVC animated:YES];
        }
    }
    else
    {
        if (indexPath.row == 0) {
            JAboutController *userInfoVC = [[JAboutController alloc]init];
            [self.navigationController pushViewController:userInfoVC animated:YES];
        }
        else
        {
            JFeedbackController *userInfoVC = [[JFeedbackController alloc]init];
            userInfoVC.inputType = 0;
            [self.navigationController pushViewController:userInfoVC animated:YES];
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

- (void)leftButtonClick:(UIButton *)leftButton
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
